﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace CollisionDetectionSandbox
{
    class ScoreScreen : Screen
    {
        Texture2D mScoreScreenBackground;
        Button mBackButton, mBackHover;
        ScoreUpdater su;

        SpriteFont Font1;
        Vector2 FontPosStart;
        

         public ScoreScreen(ContentManager theContent, EventHandler theScreenEvent)
            : base(theScreenEvent)
        {
            //Load the background texture for the screen
            su = new ScoreUpdater();
            mScoreScreenBackground = theContent.Load<Texture2D>("Main Textures/HighScoreScreen");

            //mBackButton = new Button(theContent, "ButtonTextures/button_menu2", ZeusGame.GAME_WIDTH/2-50, ZeusGame.GAME_HEIGHT-75);


            Font1 = theContent.Load<SpriteFont>("Font/Font1");
            FontPosStart = new Vector2(GameScreen.GAME_WIDTH - 600, 210);
            mBackButton = new Button(theContent, "ButtonTextures/button_menu2", ZeusGame.xpos, ZeusGame.ypos + 250);
            mBackHover = new Button(theContent, "ButtonTextures/buttonhover_menu2", ZeusGame.xpos, ZeusGame.ypos + 250);

        }

         public override void Update(GameTime theTime)
         {
             MouseState state = Mouse.GetState();
             int mx = state.X;
             int my = state.Y;
            if (state.LeftButton == ButtonState.Pressed)
            {
                if (mBackButton.hit_image(mx, my))
                {
                    ScreenEvent.Invoke(this, new EventArgs());
                }
            }
             base.Update(theTime);
         }

        public override void Draw(SpriteBatch theBatch)
         {
             theBatch.Draw(mScoreScreenBackground, Vector2.Zero, Color.White);
             List<int> Scores = su.getScores();
             List<string> Names = su.getNames();

             Vector2 fontPos = new Vector2(FontPosStart.X, FontPosStart.Y);

             for (int i = 1; i <= Names.Count; i++)
             {
                 string strDraw = i.ToString() + ".   " + Scores[i - 1] + "       " + Names[i - 1];

                 Vector2 FontOrigin0 = Font1.MeasureString(strDraw) / Font1.MeasureString(strDraw);
                 

                 theBatch.DrawString(Font1, strDraw, fontPos, Color.Maroon,
                  0, FontOrigin0, 1.0f, SpriteEffects.None, 0.5f);

                 fontPos = new Vector2(fontPos.X, fontPos.Y + 20);
             }

             MouseState state = Mouse.GetState();
             int mx = state.X;
             int my = state.Y;

             if (mBackButton.hit_image(mx, my))
             {
                 mBackHover.Draw(theBatch);
             }
             else mBackButton.Draw(theBatch);

             base.Draw(theBatch);
         }
    }
}
